package cn.ztelovecly.springboot.framework.util;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;

import java.io.FileReader;

/**
 * Created by 范智凝 on 2014-10-24 13:00:30.
 *
 * @author 范智凝
 */
public class ProjectUtil {

    public static String getProjectVersion(){
        Model model = null;
        FileReader reader = null;
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        try {
            reader = new FileReader("pom.xml");
            model = mavenreader.read(reader);
            //model.setPomFile("pom.xml");
        }catch(Exception ex){}
        MavenProject project = new MavenProject(model);

        return project.getVersion();
    }

    public static String getProjectName(){
        Model model = null;
        FileReader reader = null;
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        try {
            reader = new FileReader("pom.xml");
            model = mavenreader.read(reader);
            //model.setPomFile("pom.xml");
        }catch(Exception ex){}
        MavenProject project = new MavenProject(model);

        return project.getName();
    }
}
